﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Dapper.Data.Implement;
using Dapper.Data.Service;
using Dapper.Modle;
using System.Reflection;

namespace Dapper.Data
{
    public class DateService
    {
        private static IContainer container;
        static DateService()
        {
            ContainerBuilder builder = new ContainerBuilder();
            var assembly = Assembly.GetExecutingAssembly();
            builder.RegisterAssemblyTypes(assembly).Where(x => x.Name.EndsWith("DataImpl")).AsImplementedInterfaces().SingleInstance();
            container = builder.Build();
        }

        public static IUserDateService IUserDateService
        {
            get
            {
                return container.Resolve<IUserDateService>();
            }
        }

        public static IActionDateService IActionDateService
        {
            get
            {
                return container.Resolve<IActionDateService>();
            }
        }
    }

    public class DateService<T>
    {
        private static IContainer container;
        static DateService()
        {
            ContainerBuilder builder = new ContainerBuilder();
            builder.RegisterGeneric(typeof(ActionDateImpl<>)).As(typeof(IActionDateService<>)).SingleInstance();
            container = builder.Build();
        }

        public static IActionDateService<T> IActionDateService
        {
            get
            {
                return container.Resolve<IActionDateService<T>>();
            }
        }
    }
}
